package com.xzy.utils;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class FileUtils {

    public  static String getContent(String fileName) {
        String content = null;
        try {
            FileReader fr = new FileReader(fileName);
            int read = fr.read();
            content = String.valueOf((char) read);
            while (read != -1) {
                read = fr.read();
                content += (char) read;
            }
            fr.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return content;
    }
    public static String getUrl(String text,int userId)
    {
        SimpleDateFormat sFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        Calendar calendar = Calendar.getInstance();
        String time = sFormat.format(calendar.getTime());
        String path = "C:\\question";
        String fileName = null;
        try {
            fileName = time + "_" + userId + ".txt";
            File f = new File(path + "\\" + fileName);
            FileWriter fw = new FileWriter(f);
            fw.write(text);
            fw.flush();
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return path+"\\"+fileName;
    }


}
